package com.byt.consultation.viewmodel;

import com.byt.base.activity.IBaseView;
import com.byt.base.model.BaseModel;
import com.byt.base.utils.Utils;
import com.byt.base.viewmodel.BaseViewModel;
import com.byt.common.bean.ConsultaBean;
import com.byt.consultation.bean.BageNum;
import com.byt.consultation.bean.MainBanner;
import com.byt.consultation.model.ConsultModel;

import java.util.List;

public class ConsultViewModel extends BaseViewModel<ConsultViewModel.IConsultUserView, ConsultModel> implements
        ConsultModel.IConsultModelListener<List<ConsultaBean>> {

    public ConsultViewModel(long memberId, long infoId) {
        model = new ConsultModel(memberId, infoId);
        model.register(this);
        model.getCachedDataAndLoad();
    }

    public void tryToRefresh() {
        model.refresh();
    }

    public void onBannerImg() {
        model.onBannerImg();
    }

    public void onBageNum() {
        model.onBageNum();
    }

    @Override
    public void onLoadFinish(BaseModel model, List<ConsultaBean> data) {
        if (Utils.isEmpty(data)) {
            getPageView().showEmpty();
        } else {
            getPageView().onConsultLoaded(data);
        }
    }

    @Override
    public void onLoadFail(BaseModel model, String msg) {
        if (getPageView() != null) {
            getPageView().onRefreshFailure(msg);
        }
    }

    @Override
    public void onBannerImg(List<MainBanner> banners) {
        if (getPageView() != null) {
            getPageView().onBannerImg(banners);
        }
    }

    @Override
    public void onBageNum(BageNum bageNum) {
        if (getPageView() != null) {
            getPageView().onBageNum(bageNum);
        }
    }


    public interface IConsultUserView extends IBaseView {

        void onConsultLoaded(List<ConsultaBean> users);

        void onBannerImg(List<MainBanner> banners);

        void onBageNum(BageNum bageNum);
    }
}
